package com.shujia.hbase;

import java.sql.*;

public class Demo07PhoenixJDBC {
    public static void main(String[] args) throws SQLException {
        // 建立连接
        Connection conn = DriverManager.getConnection("jdbc:phoenix:master,node1,node2:2181");

        String queryClazz = "理科一班"; // 基于班级 将所有学生数据都查出来

        // 创建statement
        PreparedStatement pSt = conn.prepareStatement("select sid,\"name\",\"age\",\"gender\",\"clazz\" from \"stu_batch\" where \"clazz\"=?");

        // 设置参数，有几个问号 就需要设置几个参数
        pSt.setString(1, queryClazz);

        // 执行SQL 获取返回的结果
        ResultSet resultSet = pSt.executeQuery();

        while (resultSet.next()) {
            String id = resultSet.getString("sid");
            String name = resultSet.getString("name");
            String age = resultSet.getString("age");
            String gender = resultSet.getString("gender");
            String clazz = resultSet.getString("clazz");

            System.out.println(id + "," + name + "," + age + "," + gender + "," + clazz);
        }

        // 关闭连接
        pSt.close();
        conn.close();


    }
}
